{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 183,
     "output_extras": [
      {
       "item_id": 3
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 2785,
     "status": "ok",
     "timestamp": 1520162592467,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "mtR1lLU5D2TV",
    "outputId": "938f8c07-f1c8-4a4a-c3d0-09cf564a6a79"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting keras\n",
      "  Downloading Keras-2.1.4-py2.py3-none-any.whl (322kB)\n",
      "\u001b[K    100% |████████████████████████████████| 327kB 2.5MB/s \n",
      "\u001b[?25hRequirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.6/dist-packages (from keras)\n",
      "Requirement already satisfied: pyyaml in /usr/local/lib/python3.6/dist-packages (from keras)\n",
      "Requirement already satisfied: scipy>=0.14 in /usr/local/lib/python3.6/dist-packages (from keras)\n",
      "Requirement already satisfied: numpy>=1.9.1 in /usr/local/lib/python3.6/dist-packages (from keras)\n",
      "Installing collected packages: keras\n",
      "Successfully installed keras-2.1.4\n"
     ]
    }
   ],
   "source": [
    "!pip3 install keras"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 552,
     "output_extras": [
      {
       "item_id": 3
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 4208,
     "status": "ok",
     "timestamp": 1520170634766,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "2PnDsuyaM30g",
    "outputId": "5370cf69-a04b-4a6a-dd55-7ff2dbee264e"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[?1h\u001b=\u001b[H\u001b[2J\u001b[mtop - 13:37:11 up  8:30,  0 users,  load average: 0.02, 0.42, 0.60\u001b[m\u001b[m\u001b[m\u001b[m\u001b[K\n",
      "Tasks:\u001b[m\u001b[m\u001b[1m   7 \u001b[m\u001b[mtotal,\u001b[m\u001b[m\u001b[1m   1 \u001b[m\u001b[mrunning,\u001b[m\u001b[m\u001b[1m   6 \u001b[m\u001b[msleeping,\u001b[m\u001b[m\u001b[1m   0 \u001b[m\u001b[mstopped,\u001b[m\u001b[m\u001b[1m   0 \u001b[m\u001b[mzombie\u001b[m\u001b[m\u001b[m\u001b[m\u001b[K\n",
      "%Cpu(s):\u001b[m\u001b[m\u001b[1m  2.3 \u001b[m\u001b[mus,\u001b[m\u001b[m\u001b[1m  1.0 \u001b[m\u001b[msy,\u001b[m\u001b[m\u001b[1m  0.0 \u001b[m\u001b[mni,\u001b[m\u001b[m\u001b[1m 96.7 \u001b[m\u001b[mid,\u001b[m\u001b[m\u001b[1m  0.0 \u001b[m\u001b[mwa,\u001b[m\u001b[m\u001b[1m  0.0 \u001b[m\u001b[mhi,\u001b[m\u001b[m\u001b[1m  0.0 \u001b[m\u001b[msi,\u001b[m\u001b[m\u001b[1m  0.0 \u001b[m\u001b[mst\u001b[m\u001b[m\u001b[m\u001b[m\u001b[K\n",
      "KiB Mem :\u001b[m\u001b[m\u001b[1m 13341960 \u001b[m\u001b[mtotal,\u001b[m\u001b[m\u001b[1m   174132 \u001b[m\u001b[mfree,\u001b[m\u001b[m\u001b[1m  5484712 \u001b[m\u001b[mused,\u001b[m\u001b[m\u001b[1m  7683116 \u001b[m\u001b[mbuff/cache\u001b[m\u001b[m\u001b[m\u001b[m\u001b[K\n",
      "KiB Swap:\u001b[m\u001b[m\u001b[1m        0 \u001b[m\u001b[mtotal,\u001b[m\u001b[m\u001b[1m        0 \u001b[m\u001b[mfree,\u001b[m\u001b[m\u001b[1m        0 \u001b[m\u001b[mused.\u001b[m\u001b[m\u001b[1m  7237180 \u001b[m\u001b[mavail Mem \u001b[m\u001b[m\u001b[m\u001b[m\u001b[K\n",
      "\u001b[K\n",
      "\u001b[7m  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND     \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m   94 root      20   0  182908  57512  12328 S   6.7  0.4   0:54.90 jupyter-no+ \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m    1 root      20   0   39140   6576   5200 S   0.0  0.0   0:00.07 run.sh      \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m   74 root      20   0  677272  38668  21536 S   0.0  0.3   0:06.02 node        \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m   84 root      20   0  713184  66072  22908 S   0.0  0.5   0:43.55 node        \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m  115 root      20   0 42.621g 5.292g 477568 S   0.0 41.6  24:09.97 python3     \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m  267 root      20   0   33960   4860   3760 S   0.0  0.0   0:00.23 sh          \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m\u001b[1m  268 root      20   0   65356   7180   5428 R   0.0  0.1   0:00.00 top         \u001b[m\u001b[m\u001b[K\n",
      "\u001b[J\u001b[H\u001b[mtop - 13:37:14 up  8:30,  0 users,  load average: 0.02, 0.41, 0.59\u001b[m\u001b[m\u001b[m\u001b[m\u001b[K\n",
      "Tasks:\u001b[m\u001b[m\u001b[1m   7 \u001b[m\u001b[mtotal,\u001b[m\u001b[m\u001b[1m   1 \u001b[m\u001b[mrunning,\u001b[m\u001b[m\u001b[1m   6 \u001b[m\u001b[msleeping,\u001b[m\u001b[m\u001b[1m   0 \u001b[m\u001b[mstopped,\u001b[m\u001b[m\u001b[1m   0 \u001b[m\u001b[mzombie\u001b[m\u001b[m\u001b[m\u001b[m\u001b[K\n",
      "%Cpu(s):\u001b[m\u001b[m\u001b[1m  1.2 \u001b[m\u001b[mus,\u001b[m\u001b[m\u001b[1m  0.7 \u001b[m\u001b[msy,\u001b[m\u001b[m\u001b[1m  0.0 \u001b[m\u001b[mni,\u001b[m\u001b[m\u001b[1m 98.2 \u001b[m\u001b[mid,\u001b[m\u001b[m\u001b[1m  0.0 \u001b[m\u001b[mwa,\u001b[m\u001b[m\u001b[1m  0.0 \u001b[m\u001b[mhi,\u001b[m\u001b[m\u001b[1m  0.0 \u001b[m\u001b[msi,\u001b[m\u001b[m\u001b[1m  0.0 \u001b[m\u001b[mst\u001b[m\u001b[m\u001b[m\u001b[m\u001b[K\n",
      "KiB Mem :\u001b[m\u001b[m\u001b[1m 13341960 \u001b[m\u001b[mtotal,\u001b[m\u001b[m\u001b[1m   173632 \u001b[m\u001b[mfree,\u001b[m\u001b[m\u001b[1m  5485204 \u001b[m\u001b[mused,\u001b[m\u001b[m\u001b[1m  7683124 \u001b[m\u001b[mbuff/cache\u001b[m\u001b[m\u001b[m\u001b[m\u001b[K\n",
      "KiB Swap:\u001b[m\u001b[m\u001b[1m        0 \u001b[m\u001b[mtotal,\u001b[m\u001b[m\u001b[1m        0 \u001b[m\u001b[mfree,\u001b[m\u001b[m\u001b[1m        0 \u001b[m\u001b[mused.\u001b[m\u001b[m\u001b[1m  7236692 \u001b[m\u001b[mavail Mem \u001b[m\u001b[m\u001b[m\u001b[m\u001b[K\n",
      "\u001b[K\n",
      "\n",
      "\u001b[m  115 root      20   0 42.621g 5.292g 477568 S   3.3 41.6  24:10.07 python3     \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m   84 root      20   0  713184  66596  22908 S   0.3  0.5   0:43.56 node        \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m    1 root      20   0   39140   6576   5200 S   0.0  0.0   0:00.07 run.sh      \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m   74 root      20   0  677272  38932  21536 S   0.0  0.3   0:06.02 node        \u001b[m\u001b[m\u001b[K\n",
      "\u001b[m   94 root      20   0  182908  57512  12328 S   0.0  0.4   0:54.90 jupyter-no+ \u001b[m\u001b[m\u001b[K\n",
      "\n",
      "\n",
      "\u001b[J\u001b[?1l\u001b>\u001b[25;1H\n",
      "\u001b[K"
     ]
    }
   ],
   "source": [
    "!top"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     }
    },
    "colab_type": "code",
    "id": "dxwgkeLKOxkW"
   },
   "outputs": [],
   "source": [
    "!rm *.jpg.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 91,
     "output_extras": [
      {
       "item_id": 1
      },
      {
       "item_id": 2
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 2077,
     "status": "ok",
     "timestamp": 1520170660931,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "Hc36ooPpwFUG",
    "outputId": "1d440192-d999-4a18-d955-e0e49f26ad32"
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x_train shape: (60000, 28, 28, 1)\n",
      "60000 train samples\n",
      "10000 test samples\n"
     ]
    }
   ],
   "source": [
    "'''Trains a simple convnet on the MNIST dataset.\n",
    "Gets to 99.25% test accuracy after 12 epochs\n",
    "(there is still a lot of margin for parameter tuning).\n",
    "16 seconds per epoch on a GRID K520 GPU.\n",
    "'''\n",
    "\n",
    "from __future__ import print_function\n",
    "import keras\n",
    "from keras.datasets import mnist\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense, Dropout, Flatten\n",
    "from keras.layers import Conv2D, MaxPooling2D\n",
    "from keras import backend as K\n",
    "\n",
    "batch_size = 128\n",
    "num_classes = 10\n",
    "epochs = 12\n",
    "\n",
    "# input image dimensions\n",
    "img_rows, img_cols = 28, 28\n",
    "\n",
    "# the data, split between train and test sets\n",
    "(x_train, y_train), (x_test, y_test) = mnist.load_data()\n",
    "\n",
    "if K.image_data_format() == 'channels_first':\n",
    "    x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)\n",
    "    x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)\n",
    "    input_shape = (1, img_rows, img_cols)\n",
    "else:\n",
    "    x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)\n",
    "    x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)\n",
    "    input_shape = (img_rows, img_cols, 1)\n",
    "\n",
    "x_train = x_train.astype('float32')\n",
    "x_test = x_test.astype('float32')\n",
    "x_train /= 255\n",
    "x_test /= 255\n",
    "print('x_train shape:', x_train.shape)\n",
    "print(x_train.shape[0], 'train samples')\n",
    "print(x_test.shape[0], 'test samples')\n",
    "\n",
    "# convert class vectors to binary class matrices\n",
    "y_train = keras.utils.to_categorical(y_train, num_classes)\n",
    "y_test = keras.utils.to_categorical(y_test, num_classes)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 423,
     "output_extras": [
      {
       "item_id": 2
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 14791,
     "status": "ok",
     "timestamp": 1520162787130,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "AOkvRWXAww-0",
    "outputId": "03ecac14-6dc1-4c82-ae72-17cec56322ef"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Selecting previously unselected package libxext6:amd64.\r\n",
      "(Reading database ... \r",
      "(Reading database ... 5%\r",
      "(Reading database ... 10%\r",
      "(Reading database ... 15%\r",
      "(Reading database ... 20%\r",
      "(Reading database ... 25%\r",
      "(Reading database ... 30%\r",
      "(Reading database ... 35%\r",
      "(Reading database ... 40%\r",
      "(Reading database ... 45%\r",
      "(Reading database ... 50%\r",
      "(Reading database ... 55%\r",
      "(Reading database ... 60%\r",
      "(Reading database ... 65%\r",
      "(Reading database ... 70%\r",
      "(Reading database ... 75%\r",
      "(Reading database ... 80%\r",
      "(Reading database ... 85%\r",
      "(Reading database ... 90%\r",
      "(Reading database ... 95%\r",
      "(Reading database ... 100%\r",
      "(Reading database ... 16669 files and directories currently installed.)\r\n",
      "Preparing to unpack .../libxext6_2%3a1.3.3-1_amd64.deb ...\r\n",
      "Unpacking libxext6:amd64 (2:1.3.3-1) ...\n",
      "Selecting previously unselected package x11-common.\n",
      "Preparing to unpack .../x11-common_1%3a7.7+19ubuntu3_all.deb ...\n",
      "Unpacking x11-common (1:7.7+19ubuntu3) ...\n",
      "Selecting previously unselected package libice6:amd64.\n",
      "Preparing to unpack .../libice6_2%3a1.0.9-2_amd64.deb ...\n",
      "Unpacking libice6:amd64 (2:1.0.9-2) ...\n",
      "Selecting previously unselected package libsm6:amd64.\n",
      "Preparing to unpack .../libsm6_2%3a1.2.2-1_amd64.deb ...\n",
      "Unpacking libsm6:amd64 (2:1.2.2-1) ...\n",
      "Setting up libxext6:amd64 (2:1.3.3-1) ...\n",
      "Processing triggers for libc-bin (2.26-0ubuntu2.1) ...\n",
      "Setting up x11-common (1:7.7+19ubuntu3) ...\n",
      "update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults\n",
      "invoke-rc.d: could not determine current runlevel\n",
      "invoke-rc.d: policy-rc.d denied execution of start.\n",
      "Setting up libice6:amd64 (2:1.0.9-2) ...\n",
      "Setting up libsm6:amd64 (2:1.2.2-1) ...\n",
      "Processing triggers for libc-bin (2.26-0ubuntu2.1) ...\n"
     ]
    }
   ],
   "source": [
    "# https://opencv.org/\n",
    "!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python\n",
    "import cv2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 35,
     "output_extras": [
      {
       "item_id": 1
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 693,
     "status": "ok",
     "timestamp": 1520170694924,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "eF6blSnRwMRc",
    "outputId": "9cb240b8-85cf-4796-db45-7c7228fe29c1"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.4.0\n"
     ]
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import cv2 as cv\n",
    "import numpy as np\n",
    "print(cv.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 349,
     "output_extras": [
      {
       "item_id": 1
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 894,
     "status": "ok",
     "timestamp": 1520170698461,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "G_ikn0wtwRjS",
    "outputId": "9f4b7f64-7204-47e8-fc3e-5f9111500a7e"
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUsAAAFLCAYAAABft66eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1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cvv/yin3/+WYsWLVJFRYXna5Kk8+fP68SJ\nE5KkeDyuR48eaeHCha6qK6eXaNu7d6+uXr2qQCCgLVu2aMKECbladEbduHFDu3bt0v3795WXl6ei\noiLt3btXVVVVam1tVXFxsXbs2KH+/fs7PVSz6upqHTp0SP/5z39Sj+3cuVObNm3ybE2JREIbN25U\nY2OjEomEKisrFQ6HtX79es/W9LZDhw5p5MiR+vjjjz1f0/Pnz7VmzRo9ffpUr169UmVlpSZOnOiq\nurieJQAY8AkeADAgLAHAgLAEAAPCEgAMCEsAMCAsAcCAsAQAg/8FK7A/5GC+k2EAAAAASUVORK5C\nYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f5f14259a58>"
      ]
     },
     "metadata": {
      "tags": []
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "img = x_train[5].reshape((28, 28))\n",
    "img = np.uint8(img * 255)\n",
    "img = cv.resize(img, (56, 56))\n",
    "img = cv.Canny(img, 100, 200)\n",
    "img = cv.dilate(img, (3, 3))\n",
    "img = cv.dilate(img, (3, 3))\n",
    "img = cv.dilate(img, (3, 3))\n",
    "plt.imshow(img,cmap = 'gray')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 349,
     "output_extras": [
      {
       "item_id": 1
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 957,
     "status": "ok",
     "timestamp": 1520170805564,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "_H7A3b7W2oLm",
    "outputId": "ca1edc48-a017-4d23-b468-b7a04bcbcf68"
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUsAAAFLCAYAAABft66eAAAABHNCSVQICAgIfA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1auzdfqsKi8v18GDB1VdXZ3a1tvb\nq+bmZklSU1OTenp68tW8jNTX12vfvn2SpFtuuUXDw8ORj2n58uVas2aNJKm/v18LFy6MfEyS9MUX\nX+jcuXN64oknJEX/uxek0OKatWQ5NDSk73znO6nfFyxYoMHBwdk6fVaVlZVp3rx5k7YNDw+nLhEq\nKysjF1tpaakqKiokSZ2dnVq6dGnkYxq3atUqrVu3Ths3biyKmHbs2KH29vbU78UQkySdO3dOL7/8\nsn7605/qX//6V8HFNav3LCcq5iHpUY7t/fffV2dnpw4dOqSnnnoqtT3KMR09elSffvqpXn311Ulx\nRDGmY8eO6eGHH9bdd9/t/O9RjEmS7rvvPrW1tWnZsmU6f/68XnjhBSUSidR/L4S4Zi1ZVldXa2ho\nKPX7l19+qaqqqtk6fc5VVFQoHo9r3rx5GhgYmHSJHhUffPCBDhw4oLffflvz58+PfExnz55VZWWl\n7rzzTi1evFiJREI33XRTpGM6ceKEzp8/rxMnTujixYsqLy+P/OckSQsXLtTy5cslSffcc49uv/12\n9fX1FVRcs3YZ/thjj6mrq0uS9Mknn6i6ulo333zzbJ0+55YsWZKKr7u7W42NjXlukZ9vvvlGO3fu\n1B/+8AfddtttkqIf05kzZ3To0CFJ/7sNdO3atcjHtHfvXv3tb3/TX//6Vz3zzDNqbW2NfEyS9N57\n7+mdd96RJA0ODurSpUt6+umnCyquWZ2ibffu3Tpz5oxisZg2bdqkRYsWzdaps+rs2bPasWOHLly4\noLKyMi1cuFC7d+9We3u7rl+/rpqaGm3btk1z5szJd1PNOjo6tH//fn33u99Nbdu+fbtef/31yMYU\nj8f12muvqb+/X/F4XG1tbaqtrdWGDRsiG9NE+/fv11133aXHH3888jFdvXpV69at09dff62RkRG1\ntbVp8eLFBRUX81kCgAEjeADAgGQJAAYkSwAwIFkCgAHJEgAMSJYAYECyBACD/wNjMw1aEPcDWAAA\nAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f5ecc813eb8>"
      ]
     },
     "metadata": {
      "tags": []
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "img = cv.imread(\"9.jpg\", 0)\n",
    "#img = img[:, int(img.shape[1] * 0.2) : int(img.shape[1] * 0.8)]\n",
    "#img = cv.resize(img, (56, 56))\n",
    "#edges = cv.Canny(img, 100, 200)\n",
    "plt.imshow(img,cmap = 'gray')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     }
    },
    "colab_type": "code",
    "id": "7DMQ_j_o3tgx"
   },
   "outputs": [],
   "source": [
    "x_train_real = []\n",
    "for i in range(x_train.shape[0]):\n",
    "  img = x_train[i].reshape((28, 28))\n",
    "  img = np.uint8(img * 255)\n",
    "  img = cv.resize(img, (56, 56))\n",
    "  img = cv.Canny(img, 100, 200)\n",
    "  img = cv.dilate(img, (3, 3))\n",
    "  img = cv.dilate(img, (3, 3))\n",
    "  img = cv.dilate(img, (3, 3))\n",
    "  img = img / 255\n",
    "  x_train_real.append(img.reshape((56, 56, 1)))\n",
    "  \n",
    "x_train_real = np.array(x_train_real)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 35,
     "output_extras": [
      {
       "item_id": 1
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 1100,
     "status": "ok",
     "timestamp": 1520170824495,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "XRgLPwJ-7D-6",
    "outputId": "6ad3e0e8-304c-4504-f331-4e6fb5a360a7"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(60000, 56, 56, 1)"
      ]
     },
     "execution_count": 14,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train_real.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     }
    },
    "colab_type": "code",
    "id": "q74Xz02T4VN0"
   },
   "outputs": [],
   "source": [
    "x_test_real = []\n",
    "for i in range(x_test.shape[0]):\n",
    "  img = x_test[i].reshape((28, 28))\n",
    "  img = np.uint8(img * 255)\n",
    "  img = cv.resize(img, (56, 56))\n",
    "  img = cv.Canny(img, 100, 200)\n",
    "  img = cv.dilate(img, (3, 3))\n",
    "  img = cv.dilate(img, (3, 3))\n",
    "  img = cv.dilate(img, (3, 3))\n",
    "  img = img / 255\n",
    "  x_test_real.append(img.reshape((56, 56, 1)))\n",
    "\n",
    "x_test_real = np.array(x_test_real)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 535,
     "output_extras": [
      {
       "item_id": 50
      },
      {
       "item_id": 128
      },
      {
       "item_id": 201
      },
      {
       "item_id": 351
      },
      {
       "item_id": 480
      },
      {
       "item_id": 608
      },
      {
       "item_id": 751
      },
      {
       "item_id": 885
      },
      {
       "item_id": 1028
      },
      {
       "item_id": 1165
      },
      {
       "item_id": 1308
      },
      {
       "item_id": 1324
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 615875,
     "status": "ok",
     "timestamp": 1520171443731,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "iwbnz6NNESVj",
    "outputId": "4e07cf7a-4b7a-4b5b-9db9-1bcc76d386d6"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 60000 samples, validate on 10000 samples\n",
      "Epoch 1/12\n",
      "60000/60000 [==============================] - 53s 881us/step - loss: 0.2535 - acc: 0.9194 - val_loss: 0.0531 - val_acc: 0.9817\n",
      "Epoch 2/12\n",
      "13952/60000 [=====>........................] - ETA: 37s - loss: 0.0773 - acc: 0.976960000/60000 [==============================] - 51s 845us/step - loss: 0.0714 - acc: 0.9786 - val_loss: 0.0417 - val_acc: 0.9860\n",
      "Epoch 3/12\n",
      "39680/60000 [==================>...........] - ETA: 16s - loss: 0.0527 - acc: 0.984160000/60000 [==============================] - 51s 845us/step - loss: 0.0510 - acc: 0.9846 - val_loss: 0.0322 - val_acc: 0.9885\n",
      "Epoch 4/12\n",
      "49280/60000 [=======================>......] - ETA: 8s - loss: 0.0379 - acc: 0.988060000/60000 [==============================] - 51s 844us/step - loss: 0.0380 - acc: 0.9880 - val_loss: 0.0340 - val_acc: 0.9902\n",
      "Epoch 5/12\n",
      "53248/60000 [=========================>....] - ETA: 5s - loss: 0.0330 - acc: 0.989860000/60000 [==============================] - 51s 847us/step - loss: 0.0323 - acc: 0.9900 - val_loss: 0.0321 - val_acc: 0.9906\n",
      "Epoch 6/12\n",
      "54272/60000 [==========================>...] - ETA: 4s - loss: 0.0263 - acc: 0.991860000/60000 [==============================] - 51s 846us/step - loss: 0.0268 - acc: 0.9916 - val_loss: 0.0314 - val_acc: 0.9895\n",
      "Epoch 7/12\n",
      "54784/60000 [==========================>...] - ETA: 4s - loss: 0.0203 - acc: 0.993260000/60000 [==============================] - 51s 847us/step - loss: 0.0207 - acc: 0.9932 - val_loss: 0.0286 - val_acc: 0.9909\n",
      "Epoch 8/12\n",
      "54656/60000 [==========================>...] - ETA: 4s - loss: 0.0184 - acc: 0.993960000/60000 [==============================] - 51s 846us/step - loss: 0.0185 - acc: 0.9938 - val_loss: 0.0249 - val_acc: 0.9933\n",
      "Epoch 9/12\n",
      "54784/60000 [==========================>...] - ETA: 4s - loss: 0.0164 - acc: 0.994360000/60000 [==============================] - 51s 845us/step - loss: 0.0163 - acc: 0.9944 - val_loss: 0.0318 - val_acc: 0.9902\n",
      "Epoch 10/12\n",
      "54912/60000 [==========================>...] - ETA: 4s - loss: 0.0141 - acc: 0.995760000/60000 [==============================] - 51s 848us/step - loss: 0.0138 - acc: 0.9958 - val_loss: 0.0314 - val_acc: 0.9925\n",
      "Epoch 11/12\n",
      "54528/60000 [==========================>...] - ETA: 4s - loss: 0.0119 - acc: 0.996560000/60000 [==============================] - 51s 842us/step - loss: 0.0119 - acc: 0.9963 - val_loss: 0.0308 - val_acc: 0.9912\n",
      "Epoch 12/12\n",
      "53888/60000 [=========================>....] - ETA: 4s - loss: 0.0110 - acc: 0.996360000/60000 [==============================] - 51s 847us/step - loss: 0.0109 - acc: 0.9963 - val_loss: 0.0360 - val_acc: 0.9915\n",
      "Test loss: 0.035972525724563706\n",
      "Test accuracy: 0.9915\n"
     ]
    }
   ],
   "source": [
    "\n",
    "model = Sequential()\n",
    "model.add(Conv2D(32, kernel_size=(3, 3),\n",
    "                 activation='relu',\n",
    "                 input_shape=(56, 56, 1)))\n",
    "model.add(Conv2D(64, (3, 3), activation='relu'))\n",
    "model.add(MaxPooling2D(pool_size=(2, 2)))\n",
    "model.add(Conv2D(64, kernel_size=(3, 3),\n",
    "                 activation='relu',\n",
    "                 input_shape=(56, 56, 1)))\n",
    "model.add(Conv2D(128, (3, 3), activation='relu'))\n",
    "model.add(MaxPooling2D(pool_size=(2, 2)))\n",
    "model.add(Dropout(0.25))\n",
    "model.add(Flatten())\n",
    "model.add(Dense(256, activation='relu'))\n",
    "model.add(Dropout(0.5))\n",
    "model.add(Dense(num_classes, activation='softmax'))\n",
    "\n",
    "model.compile(loss=keras.losses.categorical_crossentropy,\n",
    "              optimizer=keras.optimizers.Adadelta(),\n",
    "              metrics=['accuracy'])\n",
    "\n",
    "model.fit(x_train_real, y_train,\n",
    "          batch_size=batch_size,\n",
    "          epochs=epochs,\n",
    "          verbose=1,\n",
    "          validation_data=(x_test_real, y_test))\n",
    "score = model.evaluate(x_test_real, y_test, verbose=0)\n",
    "print('Test loss:', score[0])\n",
    "print('Test accuracy:', score[1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     }
    },
    "colab_type": "code",
    "id": "RAzUeqBTFRk2"
   },
   "outputs": [],
   "source": [
    "model.save(\"model.h5\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 1845,
     "output_extras": [
      {
       "item_id": 16
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 5655,
     "status": "ok",
     "timestamp": 1520170796954,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "8HLMth8wFUjH",
    "outputId": "877a31e4-a694-487b-81fb-e36dc0c54676"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--2018-03-04 13:39:51--  https://qasd.tk:8021/9.jpg\r\n",
      "Resolving qasd.tk (qasd.tk)... 45.77.125.95\n",
      "Connecting to qasd.tk (qasd.tk)|45.77.125.95|:8021... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 1638 (1.6K) [image/jpeg]\n",
      "Saving to: ‘9.jpg’\n",
      "\n",
      "9.jpg               100%[===================>]   1.60K  --.-KB/s    in 0s      \n",
      "\n",
      "2018-03-04 13:39:51 (336 MB/s) - ‘9.jpg’ saved [1638/1638]\n",
      "\n",
      "--2018-03-04 13:39:52--  https://qasd.tk:8021/8.jpg\n",
      "Resolving qasd.tk (qasd.tk)... 45.77.125.95\n",
      "Connecting to qasd.tk (qasd.tk)|45.77.125.95|:8021... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 1576 (1.5K) [image/jpeg]\n",
      "Saving to: ‘8.jpg’\n",
      "\n",
      "8.jpg               100%[===================>]   1.54K  --.-KB/s    in 0s      \n",
      "\n",
      "2018-03-04 13:39:52 (61.0 MB/s) - ‘8.jpg’ saved [1576/1576]\n",
      "\n",
      "--2018-03-04 13:39:52--  https://qasd.tk:8021/7.jpg\n",
      "Resolving qasd.tk (qasd.tk)... 45.77.125.95\n",
      "Connecting to qasd.tk (qasd.tk)|45.77.125.95|:8021... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 1432 (1.4K) [image/jpeg]\n",
      "Saving to: ‘7.jpg’\n",
      "\n",
      "7.jpg               100%[===================>]   1.40K  --.-KB/s    in 0s      \n",
      "\n",
      "2018-03-04 13:39:53 (303 MB/s) - ‘7.jpg’ saved [1432/1432]\n",
      "\n",
      "--2018-03-04 13:39:53--  https://qasd.tk:8021/6.jpg\n",
      "Resolving qasd.tk (qasd.tk)... 45.77.125.95\n",
      "Connecting to qasd.tk (qasd.tk)|45.77.125.95|:8021... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 1829 (1.8K) [image/jpeg]\n",
      "Saving to: ‘6.jpg’\n",
      "\n",
      "6.jpg               100%[===================>]   1.79K  --.-KB/s    in 0s      \n",
      "\n",
      "2018-03-04 13:39:53 (402 MB/s) - ‘6.jpg’ saved [1829/1829]\n",
      "\n",
      "--2018-03-04 13:39:53--  https://qasd.tk:8021/5.jpg\n",
      "Resolving qasd.tk (qasd.tk)... 45.77.125.95\n",
      "Connecting to qasd.tk (qasd.tk)|45.77.125.95|:8021... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 1822 (1.8K) [image/jpeg]\n",
      "Saving to: ‘5.jpg’\n",
      "\n",
      "5.jpg               100%[===================>]   1.78K  --.-KB/s    in 0s      \n",
      "\n",
      "2018-03-04 13:39:54 (446 MB/s) - ‘5.jpg’ saved [1822/1822]\n",
      "\n",
      "--2018-03-04 13:39:54--  https://qasd.tk:8021/4.jpg\n",
      "Resolving qasd.tk (qasd.tk)... 45.77.125.95\n",
      "Connecting to qasd.tk (qasd.tk)|45.77.125.95|:8021... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 1549 (1.5K) [image/jpeg]\n",
      "Saving to: ‘4.jpg’\n",
      "\n",
      "4.jpg               100%[===================>]   1.51K  --.-KB/s    in 0s      \n",
      "\n",
      "2018-03-04 13:39:54 (346 MB/s) - ‘4.jpg’ saved [1549/1549]\n",
      "\n",
      "--2018-03-04 13:39:55--  https://qasd.tk:8021/3.jpg\n",
      "Resolving qasd.tk (qasd.tk)... 45.77.125.95\n",
      "Connecting to qasd.tk (qasd.tk)|45.77.125.95|:8021... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 1682 (1.6K) [image/jpeg]\n",
      "Saving to: ‘3.jpg’\n",
      "\n",
      "3.jpg               100%[===================>]   1.64K  --.-KB/s    in 0s      \n",
      "\n",
      "2018-03-04 13:39:55 (361 MB/s) - ‘3.jpg’ saved [1682/1682]\n",
      "\n",
      "--2018-03-04 13:39:55--  https://qasd.tk:8021/2.jpg\n",
      "Resolving qasd.tk (qasd.tk)... 45.77.125.95\n",
      "Connecting to qasd.tk (qasd.tk)|45.77.125.95|:8021... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 1658 (1.6K) [image/jpeg]\n",
      "Saving to: ‘2.jpg’\n",
      "\n",
      "2.jpg               100%[===================>]   1.62K  --.-KB/s    in 0s      \n",
      "\n",
      "2018-03-04 13:39:55 (21.2 MB/s) - ‘2.jpg’ saved [1658/1658]\n",
      "\n",
      "--2018-03-04 13:39:56--  https://qasd.tk:8021/1.jpg\n",
      "Resolving qasd.tk (qasd.tk)... 45.77.125.95\n",
      "Connecting to qasd.tk (qasd.tk)|45.77.125.95|:8021... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 1503 (1.5K) [image/jpeg]\n",
      "Saving to: ‘1.jpg’\n",
      "\n",
      "1.jpg               100%[===================>]   1.47K  --.-KB/s    in 0s      \n",
      "\n",
      "2018-03-04 13:39:56 (364 MB/s) - ‘1.jpg’ saved [1503/1503]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "!wget https://qasd.tk:8021/9.jpg\n",
    "!wget https://qasd.tk:8021/8.jpg\n",
    "!wget https://qasd.tk:8021/7.jpg\n",
    "!wget https://qasd.tk:8021/6.jpg\n",
    "!wget https://qasd.tk:8021/5.jpg\n",
    "!wget https://qasd.tk:8021/4.jpg\n",
    "!wget https://qasd.tk:8021/3.jpg\n",
    "!wget https://qasd.tk:8021/2.jpg\n",
    "!wget https://qasd.tk:8021/1.jpg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 35,
     "output_extras": [
      {
       "item_id": 1
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 871,
     "status": "ok",
     "timestamp": 1520151620525,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "2JKUaGunGMLg",
    "outputId": "ae6823d5-aa09-410f-c4c8-37f40052c583"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(28, 28, 1)\n"
     ]
    }
   ],
   "source": [
    "print(input_shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     }
    },
    "colab_type": "code",
    "id": "JKttRZl1HPOO"
   },
   "outputs": [],
   "source": [
    "import keras"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     }
    },
    "colab_type": "code",
    "id": "N3ImQ6qiG_AX"
   },
   "outputs": [],
   "source": [
    "model = keras.models.load_model(\"model.h5\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 54,
     "output_extras": [
      {
       "item_id": 1
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 1007,
     "status": "ok",
     "timestamp": 1520164962777,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "EX9Ak88DLCPK",
    "outputId": "3c420e24-8be4-4f8a-bb0b-627ea2ced40e"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.jpg  3.jpg  5.jpg  7.jpg  9.jpg    model.h5\r\n",
      "2.jpg  4.jpg  6.jpg  8.jpg  datalab\r\n"
     ]
    }
   ],
   "source": [
    "!ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "colab": {
     "autoexec": {
      "startup": false,
      "wait_interval": 0
     },
     "base_uri": "https://localhost:8080/",
     "height": 515,
     "output_extras": [
      {
       "item_id": 1
      }
     ]
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 680,
     "status": "ok",
     "timestamp": 1520172128839,
     "user": {
      "displayName": "Jachin Shen",
      "photoUrl": "https://lh3.googleusercontent.com/a/default-user=s128",
      "userId": "106689561339379028936"
     },
     "user_tz": -480
    },
    "id": "1HPsGMHWItwQ",
    "outputId": "146d139d-16f3-43d1-a0b0-d0d3b3627185"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number:1\n",
      "[[1.2754163e-10 9.9998021e-01 1.9820282e-05 6.1570964e-11 2.0302664e-08\n",
      "  7.5011369e-10 2.4870316e-08 1.9719215e-10 1.8145725e-10 1.4895713e-11]]\n",
      "number:2\n",
      "[[3.6121833e-08 4.4353446e-04 9.9948090e-01 8.7488452e-08 5.2797873e-07\n",
      "  1.4302201e-10 4.5377480e-09 1.9321114e-10 7.4940355e-05 4.8811451e-08]]\n",
      "number:3\n",
      "[[7.3921444e-07 1.3254756e-06 1.6756469e-05 9.0774798e-01 1.0739082e-07\n",
      "  9.2218235e-02 1.5073532e-06 3.8613675e-06 1.7534188e-07 9.3670978e-06]]\n",
      "number:4\n",
      "[[4.2126089e-06 5.1763804e-05 6.2353702e-06 4.6279547e-05 9.7561151e-01\n",
      "  9.0470512e-06 5.1219996e-07 3.9006202e-03 1.1558494e-03 1.9214019e-02]]\n",
      "number:5\n",
      "[[4.3494488e-06 8.4551749e-07 2.1422307e-08 3.9803769e-04 2.9264041e-10\n",
      "  9.9959141e-01 2.9902347e-07 3.0083079e-06 1.0832608e-09 1.9924055e-06]]\n",
      "number:6\n",
      "[[3.6259109e-05 1.4239361e-08 1.1876340e-09 2.7917935e-07 2.4698552e-06\n",
      "  2.6935002e-01 7.3050934e-01 9.6606563e-08 9.7168304e-05 4.3458572e-06]]\n",
      "number:7\n",
      "[[1.7942203e-06 9.8542345e-01 8.4207822e-03 1.4258336e-03 6.9540288e-06\n",
      "  7.2436313e-05 3.3685517e-06 3.6139702e-03 6.8622845e-04 3.4534454e-04]]\n",
      "number:8\n",
      "[[6.2745510e-11 5.3223069e-08 2.2104183e-08 9.8232711e-10 2.2332287e-09\n",
      "  3.1365590e-07 4.0308334e-09 3.5762068e-12 9.9999964e-01 2.7769722e-09]]\n",
      "number:9\n",
      "[[3.6920822e-04 1.3152008e-04 3.6907017e-01 5.4657108e-01 1.6691602e-03\n",
      "  1.2116330e-03 1.4899864e-06 4.4528046e-05 5.5988138e-03 7.5332388e-02]]\n"
     ]
    }
   ],
   "source": [
    "for i in range(1, 10):\n",
    "  img = cv.imread(\"{}.jpg\".format(i), 0)\n",
    "  #img = img[:, int(img.shape[1] * 0.2) : int(img.shape[1] * 0.8)]\n",
    "  #img = cv.resize(img, (56, 56))\n",
    "  #edges = cv.Canny(img, 100, 200)\n",
    "  np_image_data = np.asarray(img)\n",
    "  np_image_data = np_image_data.astype('float32') / 255\n",
    "  np_image_data = np_image_data.reshape((1, 56, 56, 1))\n",
    "  print(\"number:{}\".format(i))\n",
    "  print(model.predict(np_image_data))"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "collapsed_sections": [],
   "default_view": {},
   "name": "FireNumber.ipynb",
   "provenance": [],
   "version": "0.3.2",
   "views": {}
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
